<?php

class Application_Model_Form
{
    protected $_element = null;
    protected $_tpl     = null;
    protected $_type    = null;
    /**
     * @var Application_Model_Mapper
     */
    protected $_mapper  = null;

    public function __construct(Application_Model_ModelAbstract $element, $tpl, $type, $mapper, $params = array())
    {
        $this->_element = $element;
        $this->_tpl  = './form/' . $tpl ;
        $this->_type = $type;
        $this->_mapper = $mapper;

        switch ($type) {
            case Application_Model_Factory::TYPE_RENT_CATEGORY:
            case Application_Model_Factory::TYPE_GALLERY:
                $mapper = new Application_Model_Mapper(new Application_Model_DbTable_GalleryAlbums(), new Application_Model_GalleryAlbums());
                $this->albums = $mapper->getCollection();
                $this->albumId = $params['album'];
        }
    }

    public function getTpl()
    {
        return $this->_tpl;
    }

    public function getElement()
    {
        return $this->_element;
    }

    public function getType()
    {
        return $this->_type;
    }

    public function deleteElement()
    {
        return $this->_mapper->del($this->_mapper->getTable()->getPrimaryKey() , $this->getElement()->getId());
    }
}